var lengthOfLongestSubstring = function (s) {
  const set = new Set()
  const len = s.length
  let rk = 0
  let ans = 0
  for (let i = 0; i < len; i++) {
    if (i !== 0) {
      set.delete(s[i - 1])
    }
    while (rk < len && !set.has(s[rk])) {
      set.add(s[rk])
      rk++
    }
    ans = Math.max(ans, rk - i)
  }
  return ans
}

let res = lengthOfLongestSubstring('abcabcbb')
console.log(res)
